package com.example.demo.service.Impl;


import com.example.demo.dao.IXj;
import com.example.demo.model.Xj;
import com.example.demo.service.IXjService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Administrator 董婷
 */

@Service
public class XjServiceImpl implements IXjService{

    @Autowired
    private IXj xjMapper;
    @Override
    public int insertXj(Xj xj){
        int xjValue=0;

       Xj xj1=new Xj();
        xj1.setXjid(xj.getXjid());
        List<Xj> getX=xjMapper.getAllXj(xj1);
        if(getX.size()>0){
            xjValue=-1;

        }else{
            xjValue=xjMapper.insertXj(xj);
        }

        return xjValue;
    }

    @Override
    public List<Xj> getAllXj(Xj xj) {


        return xjMapper.getAllXj(xj);
    }

    @Override
    public int updateXj(Xj xj) {
        int xjValues=0;
        if(xj.getXjid()!=0){



            xjValues=xjMapper.updateXj(xj);
        }
        return xjValues;
    }

    @Override
    public int deleteXj(Xj xj) {
        int xjValues=0;
        if(xj.getXjid()!=0)
        {
            //主键是否与其他表有关联

           xjValues=xjMapper.deleteXj(xj);
        }
        return xjValues;
    }

    @Override
    public Xj getXj(Xj xj) {
        Xj xj1=new Xj();
        if(xj.getXjid()!=0){
            xj1=xjMapper.getXj(xj);
        }
        return xj1;
    }

}
